asm
  ld sp,$23FF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"
#include "./library/pacmanldir.bas"
#include "./library/pacmanfillram.bas"
#include "./library/b1r3f0_charmapspaceintruder.zxi"

dim eee as uinteger at $2010
dim seed as uinteger at $2012
dim ee2 as uinteger at $2014
dim ee3 as uinteger at $2016
dim ee4 as uinteger at $2018
dim ee5 as uinteger at $201A
dim ex1 as uinteger at $201C
dim ey1 as uinteger at $201E

sub spaceintputchar(txp1 as uinteger,typ1 as uinteger, tch1 as uinteger,tlc1 as uinteger):
  pacmanldir($4000+(typ1*256)+(txp1*8),tlc1+((tch1 band $FF)*8),8)
  end sub

'sub writetext(txpos2 as uinteger,typos2 as uinteger,ttxt as uinteger, tleng as uinteger,tadr2 as uinteger, txor2 as uinteger)
'  dim trt2 as uinteger at $2002
'  for trt2=0 to tleng-1
'    putchar(txpos2+trt2,typos2,peek(ttxt+trt2),tadr2,txor2)
'    next
'  end sub

seed=0

for ee2=0 to 31
  for ee3=0 to 31
    seed=smsrnd(seed) 
    spaceintputchar(ee3,ee2,96+(seed mod 9),@charmap01-256)
    next:next

for ee2=0 to 15
  for ee3=0 to 15
    spaceintputchar(ee3+14,ee2+15,(ee2*16)+ee3,@charmap01-256)
    pacmandelay(1000)
    next:next

ex1=8:ey1=8:eee=0
do
  spaceintputchar(ex1,ey1,eee,@charmap01-256)

  spaceintputchar(4,1,48+(eee mod 10),@charmap01-256)
  spaceintputchar(3,1,48+(int(eee/10) mod 10),@charmap01-256)
  spaceintputchar(2,1,48+(int(eee/100) mod 10),@charmap01-256)

  ee2=in($00)
  spaceintputchar(4,3,48+(ee2 mod 10),@charmap01-256)
  spaceintputchar(3,3,48+(int(ee2/10) mod 10),@charmap01-256)
  spaceintputchar(2,3,48+(int(ee2/100) mod 10),@charmap01-256)

  ex1=ex1+((ee2 band 4)/4)-((ee2 band 8)/8)
  ey1=ey1+((ee2 band 32)/32)-((ee2 band 64)/64)

  if ex1>128 then:ex1=31:end if
  if ey1>128 then:ey1=31:end if
  if ex1>32 then:ex1=0:end if
  if ey1>32 then:ey1=0:end if


  ee2=in($01)
  spaceintputchar(4,4,48+(ee2 mod 10),@charmap01-256)
  spaceintputchar(3,4,48+(int(ee2/10) mod 10),@charmap01-256)
  spaceintputchar(2,4,48+(int(ee2/100) mod 10),@charmap01-256)

  ee2=in($03)
  spaceintputchar(4,5,48+(ee2 mod 10),@charmap01-256)
  spaceintputchar(3,5,48+(int(ee2/10) mod 10),@charmap01-256)
  spaceintputchar(2,5,48+(int(ee2/100) mod 10),@charmap01-256)


  eee=eee+1
  loop


do:loop

'---------------------------------------------------------------

